package net

import (
	"io/ioutil"
	. "mana/buyer"
	"net/http"
	"net/url"
	"strings"
)

type Neter struct {
	NetInter
}

func (*Neter) Send(url string, t Tester) (string, error) {
	Where()

	response, err := http.Get(url)
	Check(err)
	defer response.Body.Close()
	body, err := ioutil.ReadAll(response.Body)

	return string(body), err
}
func Get(url string) (string, error) {
	Where()
	resp, err := http.Get(url)
	Check(err)
	//	locat, err := resp.Location()
	//	Check(err)
	defer resp.Body.Close()
	body, err := ioutil.ReadAll(resp.Body)
	Check(err)
	return string(body), err
}
func PostForm(curl string, val url.Values) (string, error) {
	resp, err := http.PostForm(curl, val)
	defer resp.Body.Close()
	body, err := ioutil.ReadAll(resp.Body)
	Check(err)
	return string(body), err
}

func Post(curl string, val string) (string, error) {
	c := &http.Client{}
	req, err := http.NewRequest("POST", curl, strings.NewReader(val))

	Check(err)
	req.Header.Add("Content-Type", "application/x-www-form-urlencoded")

	resp, err := c.Do(req)
	println("url:", req.URL.String())
	defer resp.Body.Close()
	body, err := ioutil.ReadAll(resp.Body)
	Check(err)
	return string(body), err
}

func (*Neter) Recive() {

}
